<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('下级办理中T')"/>
    <link th:href="@{/ajax/libs/bootstrap-switch/bootstrap-switch.min.css}" rel="stylesheet">
</head>
<style>
    .smsnote {
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
    }
    .modal {
        width:100%;
        top: 50%;
        left: 60%;
        transform: translate(-50%, -50%);
    }
</style>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>
                        <li>
                            工单编号：<input type="text" name="workFormNO"/>
                        </li>
                        <li>
                            派发单位：<input type="text" name="sdeptName"/>
                        </li>
                        <li>
                            承办部门：<input type="text" name="sbDeptName"/>
                        </li>
                        <li>
                            催办件：<select name="formType">
                            <option value="">请选择</option>
                            <option value="催办件">催办件</option>
                        </select>
                        </li>
                        <li class="select-time">
                            <label>签收时间： </label>
                            <input type="text" class="time-input mr10" id="signStartTime" placeholder="开始时间"
                                   name="signBeginTime"/>
                            <input type="text" class="time-input" id="signEndTime" placeholder="结束时间"
                                   name="signEndTime"/>
                        </li>
                        <li class="select-time">
                            <label>办理期限： </label>
                            <input type="text" class="time-input mr10" id="startTime" placeholder="开始时间"
                                   name="beginTime"/>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="endTime"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm " id="toolbar" role="group">
            <a class="btn btn-success single disabled" onclick="OnQxListShowWin()">
                <i class="fa fa-info-circle"></i> 详情
            </a>
<!--            <a class="btn btn-success single disabled" onclick="OnQxListEditWin()">-->
<!--                <i class="fa fa-edit"></i> 编辑-->
<!--            </a>-->
            <a class="btn btn-success single disabled" onclick="sendBackManage()">
                <i class="fa fa-external-link"></i> 派单管理
            </a>
            <a class="btn btn-success multiple disabled" onclick="printX()">
                <i class="fa fa-print"></i> 转办单
            </a>
            <a class="btn btn-danger multiple disabled" onclick="urgeTransact()">
                <i class="fa fa-clock-o"></i> 催办
            </a>
            <a class="btn btn-info" onclick="exportUrgeExcel()">
                <i class="fa fa-download"></i> 导出详情
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>

        <!-- Modal -->
        <div class="modal" id="smsInformModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content" style="width: 320px;">
                    <div class="modal-header" style="height: 42px;">
                        <h5 style="font-size: 14px">确认催办所选工单？</h5>
                        <button type="button" class="close" style="margin-top: -30px;" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <div class="smsnote">
                            <label style="width: 120px;color: #1453dc;">是否开启短信通知：</label>
                            <div>
                                <input type="checkbox" name="smsInform">
                            </div>
                            <input type="hidden" id="smsInform" value="0">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary" onclick="ackTransact()">确认</button>
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:src="@{/common/js/common.js}"></script>
<script th:src="@{/ajax/libs/bootstrap-switch/bootstrap-switch.min.js}"></script>
<script th:inline="javascript">
    var prefix = ctx + "gaoxin/system/mTelWF";

    $(function () {
        var options = {
            url: prefix + "/rCity/listSonWaitJson",
            sortName: "myPkVal",
            sortOrder: "desc",
            uniqueId: "myPkVal",
            updateUrl: prefix + "/rCity/sendBackChk/{id}",
            modalName: "下级办理中工单",
            fixedColumns: true,
            fixedNumber: 1,
            fixedRightNumber: 1,
            rowStyle: rowStyle,
            columns: [{
                checkbox: true
            },
                {field: 'ck', checkbox: true, title: '&nbsp;',visible:false},
                {field: 'myPkVal', title: 'pkid', hidden: true,visible:false},
                {field: 'twfpk', title: 'twfpk', hidden: true,visible:false},
                {field: 'telpk', title: 'telpk', hidden: true,visible:false},
                {field: 'fDNo', title: 'fDNo', hidden: true,visible:false},
                {field:'pid',title:'pid',visible:false},
                {field: 'SBDeptID', title: 'SBDeptID', hidden: true,visible:false},
                {field: 'myTwfNO', title: '工单编号', align: 'left', halign: 'center', sortable: true,formatter:function(value,row,index){return fmtScanByNO(value,row,index);}},
                {field: 'myTwfTopic', title: '工单主题', align: 'left', halign: 'center'},
                {field: 'FmContent', title: '工单内容', align: 'center',formatter:function (value, row, index,field) {
                        var obj = rowStyle(row)
                        if(obj == '')
                            return "<span style='cursor: pointer;' title='"+value+"'>"+value+"</span>"
                        if(obj.css.color == 'blue')
                            return "<span style='cursor: pointer;color: blue;font-weight: bold;' title='"+value+"'>"+value+"</span>"
                        else if(obj.css.color == 'red')
                            return "<span style='cursor: pointer;color: red;font-weight: bold;' title='"+value+"'>"+value+"</span>"
                        else if(obj.css.color == 'darkcyan')
                            return "<span style='cursor: pointer;color: darkcyan;font-weight: bold;' title='"+value+"'>"+value+"</span>"
                    },
                    cellStyle: cellEllipsis},
                {field: 'SBDeptName', title: '承办部门', align: 'left', halign: 'center', sortable: true},
                {field: 'SeqName', title: '交办次序', align: 'center'},
                // {field: 'SortName', title: '性质', align: 'center', sortable: true},
                {field: 'BackLimit', title: '办理期限', align: 'center', sortable: true},
                {field: 'SendRemark', title: '派发备注', align: 'left', halign: 'center'},
                {
                    field: 'SAttachPath',
                    title: '直派',
                    align: 'center',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return fmtWFormZP(value, row, index);
                    }
                },
                {
                    field: 'SendState',
                    title: '签收情况',
                    align: 'center',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return fmtSBSendState(value, row, index);
                    }
                },
                {
                    field: 'BackState',
                    title: '回复情况',
                    align: 'center',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return fmtSBBackState(value, row, index);
                    }
                },
                {
                    field: 'chgChk', title: '审查情况', align: 'center', formatter: function (value, row, index) {
                        return fmtSBBackCheck(value, row, index);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.handleTab(\'' + row.myPkVal + '\')"><i class="fa fa-edit"></i>审查</a> ');
                        // actions.push('&nbsp;&nbsp;<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="editMwfSendBack(\'' + row.myPkVal + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    //修改派单
    function OnQxListEditWin(pkId) {
        if (!pkId) {
            var row = $("#bootstrap-table").bootstrapTable('getSelections');
            pkId = row[0].myPkVal;
            var wfId = row[0].twfpk;
        }
        var url = prefix+'/rCity/sendDeptEdit/'+wfId +'/'+pkId;
        var width = '70%';
        var config = {
            id: 'dlSendToSon',
            title: '拟办部门',
            width: width,
            url: url,
            callBack: function (index, layero) {
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler();
                $.table.refresh();
            }
        };
        $.modal.openOptions(config);
    }

    function OnQxListShowWin() {
        let row = $("#bootstrap-table").bootstrapTable('getSelections');
        var url = 'gaoxin/system/test/caseDetail/' + row[0].twfpk;
        $.modal.open('电话工单-详情',url,'90%','90%');
    }

    function fmtScanByNO(value,row,index){
        return '<a href="javascript:void(0);" onclick="OnQxListShowWinByNO('+row.twfpk+')" title="单击查看详情" class="lstWd">'+value+'</a>';;
    }

    function OnQxListShowWinByNO(idWF) {
        var url = 'gaoxin/system/test/caseDetail/' + idWF;
        $.modal.open('电话工单-详情',url,'90%','90%');
    }

    function sendBackManage(){
        let row = $("#bootstrap-table").bootstrapTable('getSelections');
        let pid=row[0].pid==null?0:row[0].pid;
        var url = prefix + "/rCity/sendBackList?wfId=" + row[0].twfpk+"&telId="+row[0].telpk+"&sbId="+row[0].myPkVal+"&pid="+pid;
        var width = '80%';
        var height = '80%';
        var title = '派单管理';
        $.modal.openDialog(title,url,width,height);
    }

    // 编辑派单信息
    function editMwfSendBack(sbid) {
        // var url = 'system/mTelWF/sendDeptEditPart/' +sbid;
        // $.modal.openTab('修改-派单信息T',url);
        var url = 'gaoxin/system/mTelWF/sendDeptEditPart/'+sbid;
        var width = '70%';
        var height = '75%';
        var title = '查看-派单';
        var config = {
            id: 'dlSendToSon',
            title: '编辑-派单信息',
            width: width,
            height : height,
            url: url,
            callBack: function(index, layero) {
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler();
                $.table.refresh();
            }
        };
        $.modal.openOptions(config);
    }

    //打印转办单
    function printX() {
        var url = prefix+"/forShow/printSends";
        let row = $("#bootstrap-table").bootstrapTable('getSelections');
        if (row.length < 2) {
            url += "?ids="+row[0].myPkVal;
        }else {
            var ids = '';
            for (let i = 0; i < row.length; i++) {
                ids += row[i].myPkVal;
                if ((i+1) != row.length) {
                    ids += ","
                }
            }
            url += "?ids="+ids;
        }
        window.open(url,"printX",'left=100,top=20,height=700,width=720,toolbar=yes,menubar=yes,scrollbars=auto');
    }

    //催办派单
    function urgeTransact(){
        $("#smsInformModal").modal('show');
    }

    // 确认办理
    function ackTransact(){
        let row = $("#bootstrap-table").bootstrapTable('getSelections');
        var ids = "";
        var wfNo = "";
        var dept = "";
        $.each(row,function(index){
            ids += row[index].myPkVal + ",";
            wfNo += row[index].myTwfNO + ",";
            dept += row[index].SBDeptID + ",";
        })
        ids = ids.substr(0,ids.length - 1);
        wfNo = wfNo.substr(0,wfNo.length - 1);
        dept = dept.substr(0,dept.length - 1);
        let smsInform = $("#smsInform").val();
        $.post(prefix + "/rCity/urgeTransact", {ids:ids,wfNo:wfNo,dept:dept,smsInform:smsInform},function (res) {
            if(res.code === 0){
                //清除弹窗原数据
                $('[name="smsInform"]').bootstrapSwitch('state', false);
                $("#smsInform").val(0);
                $("#smsInformModal").modal("hide");
                $.table.refresh()
                $.modal.msgSuccess("催办成功")
            }
        },"json")
    }

    //是否开启短信通知
    $('[name="smsInform"]').bootstrapSwitch({
        onText: "是",
        offText: "否",
        onColor: "success",
        offColor: "info",
        size: "mini",
        onSwitchChange: function (event, state) {
            if (state === true) {
                $("#smsInform").val(1);
            } else {
                $("#smsInform").val(0);
            }
        }
    });

    //下级办理中电话工单数据导出
    function exportUrgeExcel(){
        let exURL =  ctx + "gaoxin/system/lookup/telUrge/export";
        let data = $("#post-form").serializeArray();
        $.modal.confirm("确定导出所有下级办理中的电话工单吗？", function() {
            $.modal.loading("正在导出数据，请稍候...");
            $.post(exURL,data,function(result) {
                if (result.code == web_status.SUCCESS) {
                    $.table.refresh()
                    window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            });
        });
    }
</script>
</body>
</html>